package com.fessc.develop.base;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fessc.develop.utils.ObjectUtil;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * 返回结果
 */
@Getter
@Setter
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class Result implements Serializable {
    //状态码
    @JsonProperty("STATUS_CODE")
    private String statusCode;

    //提示信息
    @JsonProperty("MSG")
    private String msg;

    //结果数据
    @JsonProperty("DATA")
    private Object data;

    public Result() {

    }

    public Result(String statusCode, String msg) {
        this.statusCode = statusCode;
        this.msg = msg;
    }

    /**
     * 重写toString方法，让Result对象以json字符串形式存在
     * @return
     *  Json字符串
     */
    @Override
    public String toString() {
        JSONObject json = new JSONObject();
        json.put("statusCode", this.statusCode);
        json.put("msg", this.msg);
        if (null != this.data) {
            json.put("data", ObjectUtil.modelToMap(this.data));
        }
        return json.toJSONString();
    }
}